package com.huawei.appgallery.forum.forum.forumletters.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.bean.Section;
import huawei.widget.HwSortedTextListAdapter;
import java.util.List;
import java.util.Map;
import o.azb;
import o.bqx;
import o.bst;
import o.bun.c;
import o.bun.d;
import o.buz;
import o.bvf;
import o.eqx;
import o.evx;

public class ForumLetterAdapter extends HwSortedTextListAdapter {
    private static final String TAG = "ForumLetterAdapter";
    private Context context;
    private List<Map<String, buz>> dataList;

    static class e {
        public RelativeLayout ʻ;
        public TextView ʼ;
        public TextView ʽ;
        public RelativeLayout ˊ;
        public View ˊॱ;
        public TextView ˋ;
        public LinearLayout ˋॱ;
        public TextView ˎ;
        public ImageView ˏ;
        private LinearLayout ˏॱ;
        public View ͺ;
        public TextView ॱ;
        private TextView ॱˊ;
        private View ॱˎ;
        public TextView ॱॱ;
        public ImageView ᐝ;

        private e() {
        }
    }

    public ForumLetterAdapter(Context context, List<? extends Map<String, ?>> list, String str, boolean z) {
        super(context, 0, 0, 0, list, str, z);
        this.context = context;
        this.dataList = list;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        e eVar;
        int i2;
        if (view == null) {
            view = LayoutInflater.from(this.context).inflate(d.ʻ, viewGroup, false);
            e eVar2 = new e();
            initViewHolder(view, eVar2);
            view.setTag(eVar2);
            eVar = eVar2;
        } else {
            eVar = (e) view.getTag();
        }
        buz o_buz = (buz) getItem(i);
        setViewHolderData(eVar, o_buz);
        int sectionForPosition = getSectionForPosition(i);
        int positionForSection = getPositionForSection(sectionForPosition);
        if (i == positionForSection) {
            eVar.ͺ.setVisibility(8);
            eVar.ˏॱ.setVisibility(0);
            eVar.ॱˊ.setText(o_buz.ˊ());
        } else {
            eVar.ͺ.setVisibility(0);
            eVar.ˏॱ.setVisibility(8);
        }
        View ॱ = eVar.ॱˎ;
        if (isShowSectionDivider(i, sectionForPosition)) {
            i2 = 0;
        } else {
            i2 = 8;
        }
        ॱ.setVisibility(i2);
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) eVar.ˋॱ.getLayoutParams();
        if (marginLayoutParams != null) {
            setDoubleCradTopMargin(i, positionForSection, marginLayoutParams);
            eVar.ˋॱ.setLayoutParams(marginLayoutParams);
        }
        return view;
    }

    private void setViewHolderData(final e eVar, buz o_buz) {
        final Section ˊ;
        if (o_buz.ˎ() != null) {
            ˊ = o_buz.ˎ().ˊ();
            if (ˊ != null) {
                eqx.ˏ(eVar.ˏ, ˊ.ॱ(), "app_default_icon");
                eVar.ॱ.setText(ˊ.ˏ());
                eVar.ˎ.setText(bst.ॱ(this.context, ˊ.ˎ()));
                eVar.ˋ.setText(bst.ॱ(this.context, (long) ˊ.ʻ()));
                eVar.ˊ.setOnClickListener(new evx(this) {
                    final /* synthetic */ ForumLetterAdapter ˊ;

                    public void ˋ(View view) {
                        bvf.ˋ().ˊ(this.ˊ.context, ˊ, eVar.ˋ);
                    }
                });
            }
        }
        if (o_buz.ˋ() != null) {
            eVar.ˊॱ.setVisibility(0);
            eVar.ʻ.setVisibility(0);
            ˊ = o_buz.ˋ().ˊ();
            if (ˊ != null) {
                eqx.ˏ(eVar.ᐝ, ˊ.ॱ(), "app_default_icon");
                eVar.ʽ.setText(ˊ.ˏ());
                eVar.ʼ.setText(bst.ॱ(this.context, ˊ.ˎ()));
                eVar.ॱॱ.setText(bst.ॱ(this.context, (long) ˊ.ʻ()));
                eVar.ʻ.setOnClickListener(new evx(this) {
                    final /* synthetic */ ForumLetterAdapter ॱ;

                    public void ˋ(View view) {
                        bvf.ˋ().ˊ(this.ॱ.context, ˊ, eVar.ॱॱ);
                    }
                });
                return;
            }
            return;
        }
        eVar.ˊॱ.setVisibility(8);
        eVar.ʻ.setVisibility(8);
    }

    private void initViewHolder(View view, e eVar) {
        eVar.ॱˊ = (TextView) view.findViewById(c.ˎˎ);
        eVar.ˏॱ = (LinearLayout) view.findViewById(c.ͺॱ);
        azb.ˏ(eVar.ˏॱ);
        eVar.ॱˎ = view.findViewById(c.ˎˏ);
        View findViewById = view.findViewById(c.ˋˊ);
        eVar.ˊ = (RelativeLayout) findViewById.findViewById(c.ˊˋ);
        azb.ˊ(eVar.ˊ);
        eVar.ˏ = (ImageView) findViewById.findViewById(c.ᐧ);
        eVar.ॱ = (TextView) findViewById.findViewById(c.ᐝᐝ);
        eVar.ˎ = (TextView) findViewById.findViewById(c.ـ);
        eVar.ˋ = (TextView) findViewById.findViewById(c.ˏॱ);
        findViewById = view.findViewById(c.ˊᐝ);
        eVar.ʻ = (RelativeLayout) findViewById.findViewById(c.ˊˋ);
        eVar.ᐝ = (ImageView) findViewById.findViewById(c.ᐧ);
        eVar.ʽ = (TextView) findViewById.findViewById(c.ᐝᐝ);
        eVar.ʼ = (TextView) findViewById.findViewById(c.ـ);
        eVar.ॱॱ = (TextView) findViewById.findViewById(c.ˏॱ);
        eVar.ˋॱ = (LinearLayout) view.findViewById(c.ॱᐝ);
        azb.ˎ(eVar.ˋॱ);
        eVar.ˊॱ = view.findViewById(c.ˋॱ);
        eVar.ͺ = view.findViewById(c.ᐝ);
        azb.ˋ(eVar.ͺ);
    }

    private void setDoubleCradTopMargin(int i, int i2, MarginLayoutParams marginLayoutParams) {
        if (i == i2) {
            marginLayoutParams.topMargin = -this.context.getResources().getDimensionPixelSize(o.bun.e.ॱ);
        } else {
            marginLayoutParams.topMargin = 0;
        }
    }

    private boolean isShowSectionDivider(int i, int i2) {
        try {
            Object[] sections = getSections();
            if ((sections == null || sections.length != i2 + 1) && i2 != getSectionForPosition(i + 1)) {
                return true;
            }
            return false;
        } catch (Exception e) {
            bqx.ˋ(TAG, "isShowSectionDivider error");
            return false;
        }
    }
}
